<template>
	<el-dialog v-model="dialogVisible" append-to-body :show-close="false" :close-on-click-modal="false"
		class="flex-align" style="width: 100%;height: 100%;padding: 30px 24px;margin: 0;background: transparent;">
		<template #header>
			<el-card style="width: 100%;height: 100%;" body-style="padding: 0;" shadow="never">
				<template #header>
					<div class="flex-space-between">
						<div>
							<el-text style="font-size: 16px;">
								采购到货单
							</el-text>
						</div>
						<div>
							<el-button @click="closeDialog">取消</el-button>
							<!-- <el-button @click="closeDialog">
                保存并继续创建
                <el-icon style="margin-left: 4px;">
                  <ArrowDown />
                </el-icon>
              </el-button> -->
							<el-button type="primary" @click="submitForm(vFormRef)">
								保存
							</el-button>
						</div>
					</div>
				</template>
				<el-scrollbar ref="scrollbarRef" @scroll="handleScroll"
					:style="`height: calc(100vh - 69px - ( 30px + 30px));`">
					<el-form :model="formData" :rules="rules" ref="vFormRef" label-position="top" label-width="50px"
						style="padding: 16px;">
						<el-form-item label="入库状态" prop="entryStatusId">
							<el-input class="my" readonly type="text" v-model="formData.entryStatusId" clearable>
								<template #prefix>
									<div>
										<el-check-tag
											:style="`color: ${entryStatusIndex===key?'#fff':''};${entryStatusIndex===key?`background: ${item.bg}`:''}`"
											v-for="(item,key) in entryStatusTags" :key="key"
											:checked="entryStatusIndex===key"
											@change="tagChange(key,'entryStatusId')">{{item.text}}</el-check-tag>
									</div>
								</template>
							</el-input>
						</el-form-item>
						<el-row :gutter="16">
							<el-col :span="12">
								<el-form-item label="供应商" prop="supplier">
									<el-select @clear="selectClear('supplier')" v-model="formData.supplier"
										@change="(value:any)=>selectChange(value,'supplier')" multiple ref="supplier"
										clearable>
										<el-option v-for="item in supplierOption" :key="key" :label="item?.label"
											:value="item?.value">
											<!--  -->
											<div class="flex-align-center">
												<el-icon :color="item?.color">
													<component :is="item?.icon"></component>
												</el-icon>
												<!--  -->
												<el-text style="margin-left: 6px;">{{item?.label}}</el-text>
											</div>
										</el-option>
										<!--  -->
										<template #tag>
											<div style="padding-left: 6px;">
												<div>
													<div class="flex-align-center">
														<el-icon :color="supplierOption[supplierIndex]?.color">
															<component :is="supplierOption[supplierIndex]?.icon">
															</component>
														</el-icon>
														<!--  -->
														<el-text size="small"
															style="margin-left: 6px;">{{supplierOption[supplierIndex]?.label}}</el-text>
													</div>
												</div>
											</div>
										</template>
									</el-select>
								</el-form-item>
							</el-col>
							<el-col :span="12">
								<el-form-item label="采购订单" prop="purchaseOrder">
									<el-select @clear="selectClear('purchaseOrder')" v-model="formData.purchaseOrder"
										@change="(value:any)=>selectChange(value,'purchaseOrder')" multiple
										ref="purchaseOrder" clearable>
										<el-option v-for="item in purchaseOrderOption" :key="key" :label="item?.label"
											:value="item?.value">
											<!--  -->
											<div class="flex-align-center">
												<el-icon :color="item?.color">
													<component :is="item?.icon"></component>
												</el-icon>
												<!--  -->
												<el-text style="margin-left: 6px;">{{item?.label}}</el-text>
											</div>
										</el-option>
										<!--  -->
										<template #tag>
											<div style="padding-left: 6px;">
												<div>
													<div class="flex-align-center">
														<el-icon
															:color="purchaseOrderOption[purchaseOrderIndex]?.color">
															<component
																:is="purchaseOrderOption[purchaseOrderIndex]?.icon">
															</component>
														</el-icon>
														<!--  -->
														<el-text size="small"
															style="margin-left: 6px;">{{purchaseOrderOption[purchaseOrderIndex]?.label}}</el-text>
													</div>
												</div>
											</div>
										</template>
									</el-select>
								</el-form-item>
							</el-col>
						</el-row>
						<el-form-item v-if="formData.entryStatusId===157" label="入库单" prop="warehouseReceipt">
							<el-select @clear="selectClear('warehouseReceipt')" v-model="formData.warehouseReceipt"
								@change="(value:any)=>selectChange(value,'warehouseReceipt')" multiple
								ref="warehouseReceipt" clearable>
								<el-option v-for="item in warehouseReceiptOption" :key="key" :label="item?.label"
									:value="item?.value">
									<!--  -->
									<div class="flex-align-center">
										<el-icon :color="item?.color">
											<component :is="item?.icon"></component>
										</el-icon>
										<!--  -->
										<el-text style="margin-left: 6px;">{{item?.label}}</el-text>
									</div>
								</el-option>
								<!--  -->
								<template #tag>
									<div style="padding-left: 6px;">
										<div>
											<div class="flex-align-center">
												<el-icon :color="warehouseReceiptOption[warehouseReceiptIndex]?.color">
													<component
														:is="warehouseReceiptOption[warehouseReceiptIndex]?.icon">
													</component>
												</el-icon>
												<!--  -->
												<el-text size="small"
													style="margin-left: 6px;">{{warehouseReceiptOption[warehouseReceiptIndex]?.label}}</el-text>
											</div>
										</div>
									</div>
								</template>
							</el-select>
						</el-form-item>
						<el-row :gutter="16">
							<el-col :span="12">
								<el-form-item label="申请日期" prop="requestDate">
									<el-date-picker placeholder="请选择" v-model="formData.requestDate" style="width:100%;"
										type="date" />
								</el-form-item>
							</el-col>
							<el-col :span="12">
								<el-form-item label="申请人" prop="requester">
									<el-input placeholder="请填写" type="text" v-model="formData.requester" readonly
										clearable></el-input>
								</el-form-item>
							</el-col>
						</el-row>
						<el-form-item label="备注" prop="remark">
							<el-input type="text" v-model="formData.remark" clearable></el-input>
						</el-form-item>
						<el-form-item>
							<el-input type="text" ref="salesPerson" readonly clearable class="my1">
								<template #prefix>
									<div style="margin: 0;padding: 0;">
										<el-tabs v-model="activeName" @tab-click="handleClick" class="my">
											<el-tab-pane label="到货明细" name="order">
												<div class="flex-space-between"
													style="height: 48px;padding-left: 10px;">
													<el-text type="info" size="small">
														来自 <el-text type="primary" size="small">到货明细</el-text> 的数据
														共{{formData.tableData.length}}条
													</el-text>
													<el-text>
														<el-tooltip effect="light" :hide-after="50" content="创建"
															placement="top">
															<div class="my-a" @click="setTableData">
																<el-icon size="16px" color="#409EFF">
																	<CirclePlus />
																</el-icon>
															</div>
														</el-tooltip>
													</el-text>
												</div>
												<!--  -->
												<el-scrollbar style="width: calc(100vw - 48px - 32px);height: 300px;">
													<el-table @cell-dblclick="tableCellClick" v-loading="loading"
														:data="formData.tableData" :stripe="false" table-layout="auto"
														:default-sort="{}" border style="width: 100%;height: 300px;"
														class="my">
														<el-table-column width="76" fixed="left" prop="id"
															:sortable="false">
															<template #default="scope">
																<el-tooltip effect="light" :hide-after="50" content="复制"
																	placement="top">
																	<el-button style="padding: 0;" class="my"
																		@click="copyTableData(scope.$index)"
																		:icon="DocumentAdd"></el-button>
																</el-tooltip>
																<el-tooltip effect="light" :hide-after="50" content="删除"
																	placement="top">
																	<el-button style="padding: 0;" class="my"
																		@click="deleteTableData(scope.$index)"
																		:icon="Delete"></el-button>
																</el-tooltip>
															</template>
														</el-table-column>
														<el-table-column width="140" prop="productId" label="到货产品*(可选)"
															:sortable="false">
															<template #default="scope">
																<el-form-item v-if="!scope.row.productId" class="my"
																	:prop="`tableData[${scope.$index}].productId`"
																	:rules="[{required: true,message: '到货产品必选',trigger: 'change'}]">
																	<el-input type="number" class="my-s"
																		v-model="scope.row.productId" clearable
																		readonly></el-input>
																</el-form-item>
																<el-text v-else>
																	<div class="flex-align-center"
																		v-if="scope.row?.products">
																		<el-icon :color="scope.row?.products.color">
																			<component :is="scope.row?.products.icon">
																			</component>
																		</el-icon>
																		<el-text size="small" style="margin-left: 6px;">
																			{{scope.row?.products.label}}
																		</el-text>
																	</div>
																</el-text>
															</template>
														</el-table-column>
														<el-table-column width="140" prop="unitId" label="单位"
															:sortable="false">
														</el-table-column>
														<el-table-column width="140" prop="currentInventory"
															label="当前库存数量" :sortable="false">
														</el-table-column>
														<el-table-column width="140" prop="receivedQuantity"
															label="本次到货数量*(可选)" :sortable="false">
															<template #default="scope">
																<el-form-item v-if="!scope.row.receivedQuantity"
																	class="my"
																	:prop="`tableData[${scope.$index}].receivedQuantity`"
																	:rules="[{required: true,message: '到货数量必填',trigger: 'change',
																	validator:(rule: any, value: any, callback: any)=>
																	{
																		let msg = '不能为空';
																		if(!value){
																			ElMessage.error(msg);
																			callback(new Error(msg));
																		}
																		if( value > scope.row.purchaseQuantity){
																			mag = '到货数量不能超过采购数量！';
																			ElMessage.error(msg);
																			callback(new Error(msg));
																		}
																	}
																	}]">
																	<el-input type="number" class="my-s"
																		v-model="scope.row.receivedQuantity" clearable
																		readonly></el-input>
																</el-form-item>
																<el-text v-else>{{scope.row.receivedQuantity}}</el-text>
															</template>
														</el-table-column>
														<el-table-column width="140" prop="purchaseDetailId"
															label="采购明细*(可选)" :sortable="false">
															<template #default="scope">
																<el-form-item v-if="!scope.row.purchaseDetailId"
																	class="my"
																	:prop="`tableData[${scope.$index}].purchaseDetailId`"
																	:rules="[{required: true,message: '采购明细必选',trigger: 'change'}]">
																	<el-input type="number" class="my-s"
																		v-model="scope.row.purchaseDetailId" clearable
																		readonly></el-input>
																</el-form-item>
																<el-text v-else>
																	<div class="flex-align-center"
																		v-if="scope.row?.purchaseDetail">
																		<el-icon
																			:color="scope.row?.purchaseDetail.color">
																			<component
																				:is="scope.row?.purchaseDetail.icon">
																			</component>
																		</el-icon>
																		<el-text size="small" style="margin-left: 6px;">
																			{{scope.row?.purchaseDetail.label}}
																		</el-text>
																	</div>
																</el-text>
															</template>
														</el-table-column>
														<el-table-column width="140" prop="purchaseQuantity"
															label="采购数量" :sortable="false">
														</el-table-column>
														<el-table-column width="140" prop="pendingArrivalQuantity"
															label="待到货数量" :sortable="false">
														</el-table-column>
													</el-table>
												</el-scrollbar>
											</el-tab-pane>
										</el-tabs>
									</div>
								</template>
							</el-input>
						</el-form-item>
					</el-form>
				</el-scrollbar>
				<!--  -->
			</el-card>
			<!--  -->
			<levitation ref="levitationRef" :option="selectCell.option" :types="types" :st_type="selectCell.type"
				:params="levitationParams" :observerElement="scrollbarRef" :element="element" @change="levitationChange"
				@blur="levitationBlur" />
		</template>
	</el-dialog>
</template>

<script setup lang="ts">
	import { ElLoading, ElMessage, FormInstance } from 'element-plus';
	import { onMounted, reactive, ref } from 'vue';
	import { useRoute, useRouter } from 'vue-router';
	import request from '../../../utils/request';
	import { UserFilled, WalletFilled, CirclePlus, DocumentAdd, Delete, Ship, Refresh, Van, Download, UploadFilled, CopyDocument, GoodsFilled } from '@element-plus/icons-vue';
	import { mergeObjects, formatNumber } from '../../../utils';
	import { useSelect } from '../../../utils/mixins';
	import { jwtDecode } from 'jwt-decode';
	import cookie from 'js-cookie';
	import levitation from '../../../components/levitation-form/levitation-form.vue';
	import { getShipments } from '../../../api/shipmentAPI';
	const emits = defineEmits(['update']);
	const { handSelectChange } = useSelect();
	const router = useRouter();
	const route = useRoute();
	const vFormRef = ref<FormInstance>(null);
	const loading = ref(false);
	const activeName = ref('order');
	//levitation start
	const element = ref(null);
	const levitationRef = ref(null);
	const scrollbarRef = ref(null);
	const types = ref('');
	const selectCell = ref({
		id: 0,
		property: '',
		type: '',
		option: []
	});
	const levitationParams = ref(null);
	//levitation end
	// 表单
	const formData = ref({
		entryStatusId: null, //入库状态
		supplierId: null, //供应商
		supplier: [],
		purchaseOrderId: null, //采购订单
		purchaseOrder: [],
		warehouseReceiptId: null,//入库单
		warehouseReceipt: [],
		requestDate: null,//申请日期
		requester: null,//申请人
		remark: null,//备注
		tableData: [],
	});
	//验证
	const rules = reactive({
		entryStatusId: [{ required: true, message: '不能为空', trigger: 'blur' }], //入库状态
		supplier: [{ required: true, message: '不能为空', trigger: 'blur' }],//供应商
		purchaseOrder: [{ required: true, message: '不能为空', trigger: 'blur' }],//采购订单
		warehouseReceipt: [],//入库单
		requestDate: [{ required: true, message: '不能为空', trigger: 'blur' }],//申请日期
		requester: [{ required: true, message: '不能为空', trigger: 'blur' }],//申请人
		remark: [],//备注
	});;
	//入库状态
	const entryStatusTags = ref([]);
	const entryStatusIndex = ref(-1);
	//供应商
	const supplierOption = ref([]);
	const supplierIndex = ref(-1);
	const supplier = ref(null);
	//采购订单
	const purchaseOrderOption = ref([]);
	const purchaseOrderIndex = ref(-1);
	const purchaseOrder = ref(null);
	//入库单
	const warehouseReceiptOption = ref([]);
	const warehouseReceiptIndex = ref(-1);
	const warehouseReceipt = ref(null);
	//到货产品 table
	const productOption = ref([]);
	//采购明细 table
	const purchaseDetailOption = ref([]);
	//
	const dialogVisible = ref(false);
	/**
	 * 打开弹出层
	 */
	const openDialog = () => {
		dialogVisible.value = true;
		setTimeout(async () => {
			const result = await getPageId();
			//
			if (result) {
				getentryStatus();
				getSupplierAll();
				getOrderAll();
				getwarehouseReceiptAll();
				if (!route.query.id) {
					entryStatusIndex.value = 0;
					formData.value.entryStatusId = 156;
				}
			}
		}, 10);
	}
	/**
	 * 关闭弹出层
	 */
	const closeDialog = () => {
		dialogVisible.value = false;
		vFormRef.value.resetFields();
		//清空url参数
		router.push({ query: {} });
	}
	//获取当前页面的数据
	const getPageId = async () => {
		if (!route.query.id) {
			const token = cookie.get('token');
			const decodedToken : {
				username : string
			} = jwtDecode(token);
			// console.log('decodedToken--->', decodedToken);
			//
			formData.value.requester = decodedToken?.username;
			//
			return true;
		}
		const result = await request({
			url: '/demand/selectPurchaseArrivalById',
			params: {
				id: route.query.id
			},
		});
		//
		console.log('getPageId --->', result);
		//
		formData.value = { ...result.data.t };
		formData.value.tableData = [...result.data.t.receiptDetails];
		//
		formData.value.tableData.forEach((item : any, key : number) => {
			getProductByPId(item.productId);
			getpurchaseDetailId(item.purchaseDetailId);
		});
		//
		return true;
	}
	//设置一个
	const setTableData = () => {
		formData.value.tableData.push({
			id: +new Date(),
			productId: null, //到货产品
			product: null,
			unitId: null, //单位
			currentInventory: null, //当前库存数量
			receivedQuantity: null,//本次到货数量
			purchaseDetailId: null,//采购明细
			purchaseDetail: null,
			purchaseQuantity: null,//采购数量
			pendingArrivalQuantity: null,//待到货数量
		});
	}
	//复制一个
	const copyTableData = (index : number) => {
		//...
		const item = { ...formData.value.tableData[index] };
		item.id = +new Date();
		formData.value.tableData.push(item);
	}
	//删除一个
	const deleteTableData = (index : number) => {
		formData.value.tableData.splice(index, 1);
	}
	const selectClear = (type : string) => {
		formData.value[type] = [];
	}
	const tableCellClick = (row : any, column : any, cell : HTMLTableCellElement, event : Event) => {
		if (route.query.id) {
			return;
		}
		types.value = '';
		//到货产品
		if (column.property === 'productId') {
			types.value = 'select-icon';
			selectCell.value.option = [...productOption.value];
		}
		//本次到货数量
		if (column.property === 'receivedQuantity') {
			types.value = 'number';
		}
		//采购明细
		if (column.property === 'purchaseDetailId') {
			types.value = 'select-icon';
			selectCell.value.option = [...purchaseDetailOption.value];
		}
		element.value = cell;
		//
		selectCell.value.id = row.id;
		selectCell.value.property = column.property;
		//
		levitationParams.value = row[column.property];

		setTimeout(() => {
			levitationRef.value.getElementInfo();
		}, 1);
		//
	}
	//改变
	const selectChange = (value : Array<any>, type : string, key : number) => {
		//所有下拉框的配置列表
		const typeList = [{
			type: 'supplier', //哪一个下拉框，根据ref
			option: supplierOption, //下拉列表选项
			indexVar: supplierIndex, //当前选中项
			idVar: 'supplierId', //当前id值
			blurRef: supplier, //ref
		}, {
			type: 'purchaseOrder', //哪一个下拉框，根据ref
			option: purchaseOrderOption, //下拉列表选项
			indexVar: purchaseOrderIndex, //当前选中项
			idVar: 'purchaseOrderId', //当前id值
			blurRef: purchaseOrder, //ref
			fun: getDetailById
		}, {
			type: 'warehouseReceipt', //哪一个下拉框，根据ref
			option: warehouseReceiptOption, //下拉列表选项
			indexVar: warehouseReceiptIndex, //当前选中项
			idVar: 'warehouseReceiptId', //当前id值
			blurRef: warehouseReceipt, //ref
		},];
		//
		handSelectChange(formData, typeList, value, type, key);
	}
	//tag改变
	const tagChange = (index : number, type : string) => {
		// if (type === 'entryStatusId') {
		// 	if (entryStatusIndex.value === index) {
		// 		formData.value[type] = 0;
		// 		entryStatusIndex.value = -1;
		// 		return;
		// 	}
		// 	entryStatusIndex.value = index;
		// 	formData.value[type] = entryStatusTags.value[index].value;
		// }
	}
	//获取入库状态
	const getentryStatus = async () => {
		const data = await getShipments('entry_status', 'tag');
		console.log('getentryStatus --->', data);
		entryStatusTags.value = [];
		data.forEach((item : any, key : number) => {
			entryStatusTags.value.push(item);
			if (formData.value.entryStatusId === item.value) {
				entryStatusIndex.value = key;
			}
		});
	}
	//获取所有供应商
	const getSupplierAll = async () => {
		supplierOption.value = [];
		const result = await request({
			url: '/demand/supplierAll',
		});
		//
		console.log('getSupplierAll --->', result);
		//
		result.data.t.forEach((item : any, key : number) => {
			supplierOption.value.push({
				label: `${item.supplierShortName}`,
				value: item.supplierId,
				icon: Ship,
				color: '#ff5500'
			});
			if (formData.value.supplierId === item.supplierId) {
				formData.value.supplier = [item.supplierId];
				supplierIndex.value = key;
				//
			}
		});
		//
	}
	//获取所有采购订单
	const getOrderAll = async () => {
		const result = await request({
			url: '/demand/selectOrderAll',
			params: {
				//待入库
				id: 150
			},
		});
		//
		console.log('getOrderAll --->', result);
		//
		purchaseOrderOption.value = [];
		result.data.t.list.forEach((item : any, key : number) => {
			purchaseOrderOption.value.push({
				label: `${item.purchaseOrderNumber}_${item.totalAmount}_${item.supplier.supplierShortName}`,
				value: item.purchaseOrderId,
				icon: Van,
				color: '#faa30c'
			});
			//
			if (formData.value?.purchaseOrderId === item.purchaseOrderId) {
				formData.value.purchaseOrder = [item.purchaseOrderId];
				purchaseOrderIndex.value = key;
				//
				getDetailById(item.purchaseOrderId);
			}
		});
	}
	//获取所有入库单
	const getwarehouseReceiptAll = async () => {
		const result = await request({
			url: '/demand/selectWarehouseReceiptAll',
			params: {
				pageNum: 1,
				pageSize: 1000,
			},
		});
		//
		console.log('getwarehouseReceiptAll --->', result);
		//获取入库类型
		const data = await getShipments('receipt_type');
		//
		warehouseReceiptOption.value = [];
		result.data.t.list.forEach((item : any, key : number) => {
			data.forEach((item1 : any, key1 : number) => {
				if (item.receiptTypeId === item1.value) {
					item.receiptType = item1.label;
					warehouseReceiptOption.value.push({
						label: `${item.receiptNumber}_${item1.label}`,
						value: item.receiptId,
						icon: Download,
						color: '#faa30c'
					});
					//
					if (formData.value.warehouseReceiptId === item.receiptId) {
						formData.value.purchaseOrder = [item.receiptId];
						purchaseOrderIndex.value = key;
					}
				}
				//
			});
		});
		// console.log('warehouseReceiptOption.value --->', warehouseReceiptOption.value);
	}
	//根据采购订单id
	const getDetailById = async (id : number | string) => {
		const result = await request({
			url: '/demand/selectOrderById',
			params: {
				id
			}
		});
		//
		console.log('getDetailById --->', result);
		const { order, purchaseDetailList } = result.data.t;
		//采购订单明细
		purchaseDetailOption.value = [];
		productOption.value = [];
		purchaseDetailList.forEach((item : any, key : number) => {
			purchaseDetailOption.value.push({
				label: `${order.purchaseOrderNumber}_${item.product.productName}${item.product.model}`,
				value: item.purchaseDetailId,
				icon: CopyDocument,
				color: '#82b51b'
			});

			//到货产品
			productOption.value.push({
				label: `${item.product.productName}${item.product.model} | 在库${item.product.currentInventory}件`,
				value: item.product.productId,
				icon: UploadFilled,
				color: '#5283ff'
			});
		});
	}
	//到货产品
	//根据id获取产品
	const getProductByPId = async (id : number | string) => {
		if (!id) {
			return;
		}
		const result = await request({
			url: '/demand/selectProductByPId',
			params: {
				id
			}
		});
		//
		console.log('getProductByPId --->', result);
		formData.value.tableData.forEach((item : any, key : number) => {
			if (item.productId === result.data.t.productId) {
				item.unitId = result.data.t.unitId;
				item.currentInventory = result.data.t.currentInventory;
				item.products = {
					label: `${result.data.t?.productName}${result.data.t?.model} | 在库${result.data.t?.currentInventory}件`,
					value: result.data.t.productId,
					icon: GoodsFilled,
					color: '#5283ff'
				}
			}
		});
	}
	//根据id获取采购明细
	const getpurchaseDetailId = async (id : string | number) => {
		if (!id) {
			return;
		}
		const result = await request({
			url: '/demand/selectPurchaseDetailsById',
			params: {
				id
			}
		});
		//
		console.log('getpurchaseDetailId --->', result);
		formData.value.tableData.forEach((item : any, key : number) => {
			if (item.purchaseDetailId === result.data.t.purchaseDetailId) {
				item.purchaseQuantity = result.data.t.purchaseQuantity;
				item.pendingArrivalQuantity = result.data.t.pendingArrivalQuantity
				item.purchaseDetail = {
					label: `${result.data.t?.order.purchaseOrderNumber}_${result.data.t.product.productName}${result.data.t.product.model}`,
					value: result.data.t.purchaseDetailId,
					icon: CopyDocument,
					color: '#82b51b'
				};
			}
		});
	}
	//提交表单
	const submitForm = async (formEl : FormInstance | undefined) => {
		if (!formEl) return;
		await formEl.validate(async (valid, fields) => {
			if (valid) {
				console.log('submitForm ---> ', formData.value);
				const data = { ...formData.value, receiptDetails: formData.value.tableData };
				delete data.purchaseOrder;
				delete data.supplier;
				delete data.tableData;
				delete data.warehouseReceipt;
				let type = '';
				if (!route.query.id) {
					type = '/addPurchaseArrival';
				} else {
					type = '/updatePurchaseArrival';
				}
				//
				const result = await request({
					url: '/demand' + type,
					data: data,
					method: 'post'
				});
				//
				console.log('submitForm--->', result);
				//
				if (result.data.code === 200) {
					ElMessage.success({
						message: '操作成功！'
					});
				} else {
					ElMessage.error({
						message: result.data.msg
					});
				}
				// //
				setTimeout(() => {
					closeDialog();
					emits('update');
				}, 1);
			} else {
				//
				console.log('error submit!', fields);
			}
		});
	}
	//失去焦点 ***** 重要！重要！重要！
	const levitationBlur = () => {
		element.value = null;
	}
	//内容改变
	const levitationChange = (value : string | number) => {
		// console.log('value --->', value);
		formData.value.tableData.forEach((item : any, key : number) => {
			// console.log('item.id --->', item.id, 'selectCell.value.id --->', selectCell.value.id);
			if (item.id === selectCell.value.id) {
				item[selectCell.value.property] = value;
				if (selectCell.value.property === 'productId') {
					getProductByPId(value);
				}
				if (selectCell.value.property === 'purchaseDetailId') {
					getpurchaseDetailId(value);
				}
			}
		});
	}
	//滚动
	const handleScroll = (e : any) => {
		// console.log('handleScroll --->', e);
		if (element.value === null) return;
		levitationRef.value.getElementInfo();
	}
	//
	defineExpose({
		openDialog
	});
</script>
<style>
	@import '../../../assets/css/my-form-item.css';
	@import '../../../assets/css/index.css';

	.el-scrollbar__view {
		display: block !important;
	}
</style>
<style scoped lang="scss">
	@import '../../../assets/css/index.scss';
</style>